﻿@page "/Test/TaskItem/Create"
@using FC.ViewModel.Test.TaskItemVMs;
@inherits BasePage

<ValidateForm @ref="vform" Model="@Model" OnValidSubmit="@Submit">
    <Row ItemsPerRow="ItemsPerRow.Two" RowType="RowType.Normal">

            <BootstrapInput @bind-Value="@Model.Entity.Name"  />
            <BootstrapInput @bind-Value="@Model.Entity.Description"  />
            <Select @bind-Value="@Model.Entity.IterationId" Items="@AllIterations" PlaceHolder="@WtmBlazor.Localizer["Sys.PleaseSelect"]"/>
            <Select @bind-Value="@Model.Entity.FinishedUserId" Items="@AllFrameworkUsers" PlaceHolder="@WtmBlazor.Localizer["Sys.PleaseSelect"]"/>
            <Select @bind-Value="@Model.Entity.TaskStatus"  PlaceHolder="@WtmBlazor.Localizer["Sys.PleaseSelect"]"/>
            <Select @bind-Value="@Model.Entity.ParentId" Items="@AllTaskItems" PlaceHolder="@WtmBlazor.Localizer["Sys.PleaseSelect"]"/>
    </Row>
    <div class="modal-footer table-modal-footer">
        <Button Color="Color.Primary" Icon="fa fa-save" Text="@WtmBlazor.Localizer["Sys.Close"]" OnClick="OnClose" />
        <Button Color="Color.Primary" ButtonType="ButtonType.Submit" Icon="fa fa-save" Text="@WtmBlazor.Localizer["Sys.Create"]" IsAsync="true" />
    </div>
</ValidateForm>

@code {

    private TaskItemVM Model = new TaskItemVM();
    private ValidateForm vform { get; set; }

    private List<SelectedItem> AllIterations = new List<SelectedItem>();

    private List<SelectedItem> AllFrameworkUsers = new List<SelectedItem>();

    private List<SelectedItem> AllTaskItems = new List<SelectedItem>();


    protected override async Task OnInitializedAsync()
    {

        AllIterations = await WtmBlazor.Api.CallItemsApi("/api/TaskItem/GetIterations", placeholder: WtmBlazor.Localizer["Sys.PleaseSelect"]);

        AllFrameworkUsers = await WtmBlazor.Api.CallItemsApi("/api/TaskItem/GetFrameworkUsers", placeholder: WtmBlazor.Localizer["Sys.PleaseSelect"]);

        AllTaskItems = await WtmBlazor.Api.CallItemsApi("/api/TaskItem/GetTaskItems", placeholder: WtmBlazor.Localizer["Sys.PleaseSelect"]);

        await base.OnInitializedAsync();
    }


    private async Task Submit(EditContext context)
    {
        await PostsForm(vform, "/api/TaskItem/add", (s) => "Sys.OprationSuccess");
    }

    public void OnClose()
    {
        CloseDialog();
    }

}
